Skip to content

Replace zap/pingcap logging with standard library slog#2

Merged
kyleconroy merged 1 commit intomainfrom
claude/replace-zap-with-slog-0T8k6
Apr 26, 2026
Merged

Replace zap/pingcap logging with standard library slog#2
kyleconroy merged 1 commit intomainfrom
claude/replace-zap-with-slog-0T8k6

Conversation

@kyleconroy
Copy link
Copy Markdown
Contributor

Summary

This PR migrates the codebase from using the pingcap/log wrapper around go.uber.org/zap to the standard library's log/slog package. This reduces external dependencies and leverages Go's built-in structured logging capabilities.

Key Changes

  • Logging imports: Replaced github.com/pingcap/log and go.uber.org/zap with log/slog
  • Logging calls: Updated all logging statements to use slog API:
    • log.Warn()slog.Warn()
    • log.Error()slog.Error()
    • log.Debug()slog.Debug()
    • log.Fatal()slog.Error() + os.Exit(1)
  • Attribute formatting: Converted zap attributes to slog equivalents:
    • zap.String()slog.String()
    • zap.Int()slog.Int()
    • zap.Error()slog.Any("error", err)
    • zap.Stack()slog.String("stack", string(debug.Stack()))
  • Dependencies: Removed github.com/pingcap/log and go.uber.org/zap from go.mod
  • Files modified: terror/terror.go and charset/charset.go

Notable Implementation Details

  • Stack traces are now explicitly captured using runtime/debug.Stack() instead of relying on zap's automatic stack capture
  • The MustNil() function now calls os.Exit(1) after logging instead of using log.Fatal() to maintain the same behavior
  • All structured logging attributes are preserved with equivalent slog field types

https://claude.ai/code/session_01YLqL18zVJuHKeozjDQtb1u

Switch the two logging call sites in terror and charset over to the
standard library's log/slog so we can drop the zap and pingcap/log
dependencies. Stack traces now go through runtime/debug.Stack(), and
the previous log.Fatal call becomes slog.Error followed by os.Exit(1).
@kyleconroy kyleconroy merged commit ccc4cc5 into main Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants